package com.ruoyi.device.controller;

import java.util.List;
import java.io.IOException;

import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.device.domain.TBuilding;
import com.ruoyi.device.service.ITBuildingService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 建筑Controller
 * 
 * @author li
 * @date 2025-09-22
 */
@RestController
@RequestMapping("/building")
@Tag(name = "建筑管理", description = "建筑管理相关操作API")
public class TBuildingController extends BaseController
{
    @Autowired
    private ITBuildingService tBuildingService;

    /**
     * 查询建筑列表
     */
    @RequiresPermissions("ruoyi-device:building:list")
    @GetMapping("/list")
    @Operation(summary = "查询建筑列表", description = "查询建筑列表")
    public TableDataInfo list(TBuilding tBuilding)
    {
        startPage();
        List<TBuilding> list = tBuildingService.selectTBuildingList(tBuilding);
        return getDataTable(list);
    }

    /**
     * 导出建筑列表
     */
    @Operation(summary = "导出建筑列表", description = "导出建筑列表")
    @RequiresPermissions("ruoyi-device:building:export")
    @Log(title = "建筑", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TBuilding tBuilding)
    {
        List<TBuilding> list = tBuildingService.selectTBuildingList(tBuilding);
        ExcelUtil<TBuilding> util = new ExcelUtil<TBuilding>(TBuilding.class);
        util.exportExcel(response, list, "建筑数据");
    }

    /**
     * 获取建筑详细信息
     */
    @Operation(summary = "获取建筑详细信息", description = "获取建筑详细信息")
    @RequiresPermissions("ruoyi-device:building:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id)
    {
        return success(tBuildingService.selectTBuildingById(id));
    }

    /**
     * 新增建筑
     */
    @Operation(summary = "新增建筑", description = "新增建筑")
    @RequiresPermissions("ruoyi-device:building:add")
    @Log(title = "建筑", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TBuilding tBuilding)
    {
        return toAjax(tBuildingService.insertTBuilding(tBuilding));
    }

    /**
     * 修改建筑
     */
    @Operation(summary = "修改建筑", description = "修改建筑")
    @RequiresPermissions("ruoyi-device:building:edit")
    @Log(title = "建筑", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TBuilding tBuilding)
    {
        return toAjax(tBuildingService.updateTBuilding(tBuilding));
    }

    /**
     * 删除建筑
     */
    @Operation(summary = "删除建筑", description = "删除建筑")
    @RequiresPermissions("ruoyi-device:building:remove")
    @Log(title = "建筑", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids)
    {
        return toAjax(tBuildingService.deleteTBuildingByIds(ids));
    }
}
